package ink.yql.dao;

import ink.yql.model.Point;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author YQL
 * Point持久层
 */
@Mapper
public interface PointDao {
    /**
     * 获取该用户的一类点赞
     *
     * @return 点赞对象
     */
    @Select("select * from point where puid = #{puid} and ptype=0 and pstatus=#{pstatus}")
    List<Point> getByUidPraiseStatus(@Param("puid") Integer puid, @Param("pstatus") Integer status);

    /**
     * 获取该用户的所有点赞
     *
     * @return 点赞对象
     */
    @Select("select * from point where puid = #{puid} and ptype=0")
    List<Point> getByUidPraise(@Param("puid") Integer puid);

    /**
     * 获取该用户的一类点嘘
     *
     * @return 点嘘对象
     */
    @Select("select * from point where puid = #{puid} and ptype=1 and pstatus=#{pstatus}")
    List<Point> getByUidHissStatus(@Param("puid") Integer puid, @Param("pstatus") Integer status);

    /**
     * 获取该用户的所有点嘘
     *
     * @return 点嘘对象
     */
    @Select("select * from point where puid = #{puid} and ptype=1")
    List<Point> getByUidHiss(@Param("puid") Integer puid);

    /**
     * 获取该用户被点赞数
     *
     * @return 点赞对象
     */
    @Select("select * from point where uid = #{uid} and ptype=0 and pstatus=#{pstatus}")
    List<Point> getByUidQuiltPraiseStatus(@Param("uid") Integer uid, @Param("pstatus") Integer status);

    /**
     * 获取该用户被点嘘
     *
     * @return 点嘘对象
     */
    @Select("select * from point where uid = #{uid} and ptype=1 and pstatus=#{pstatus}")
    List<Point> getByUidQuiltHissStatus(@Param("uid") Integer uid, @Param("pstatus") Integer status);

    /**
     * 查看当前的操作是否存在
     *
     * @param point 全体查询
     * @return 是否存在
     */
    @Select("select * from point where uid = #{uid} and ptype=1 and pstatus=#{pstatus} and puid =#{puid} ")
    List<Point> doesItExist(Point point);

    /**
     * 添加一个操作
     *
     * @param point 信息
     * @return 影响行数
     */
    @Insert("insert into point (puid,uid,pstatus,ptype) values(#{puid} ,#{uid} ,#{pstatus} ,#{ptype} )")
    Integer addOne(Point point);

    /**
     * 删除点击记录
     *
     * @param uid     用户id
     * @param pstatus 赞/嘘
     * @param ptype   类型
     * @return 影响行数
     */
    @Delete("delete from point where uid=#{uid} and pstatus=#{pstatus} and ptype=#{ptype} ")
    Integer deleteByUidAndPststusAndPtype(@Param("uid") Integer uid, @Param("pstatus") Integer pstatus, @Param("ptype") Integer ptype);

    /**
     * 删除点击记录
     *
     * @param luid    目标id
     * @param pstatus 赞/嘘
     * @param ptype   类型
     * @return 影响行数
     */
    @Delete("delete from point where luid=#{luid} and pstatus=#{pstatus} and ptype=#{ptype} ")
    Integer deleteByLuidAndPststusAndPtype(@Param("luid") Integer luid, @Param("pstatus") Integer pstatus, @Param("ptype") Integer ptype);

}
